home *** CD-ROM | disk | FTP | other *** search
- ; Simple example of loading and saving preference files
-
- INCDIR "include:"
- XINCLUDE "scalos/preferences.bb2"
-
- ; some strings
- prefname$ = "Example" ; Name to refer to PrefsHandle with
- preffile$ = "example.prefs" ; filename to save prefs as (does not need to be the same as the name for the prefs handle)
-
- ; Temporary memory for when we read from preferences
- Dim temp.b(256)
-
-
- ; First of all we need to allocate a PrefsHandle by name
- ; (There is no specific type for a PrefsHandle, as long as it is a long or a pointer)
- *prefhandle.l = AllocPrefsHandle_(&prefname$)
- If *prefhandle
- NPrint "PrefsHandle successfully allocated"
-
- ReadPrefsHandle_ *prefhandle, &preffile$
-
- ; We need an ID and Tag value to refer to a specific preference with
- ; so we create that here (or you could just use them in the library calls)
- ; Remember that the ID must be a long created from 4 ASCII characters
- ; and the Tag cannot be 0
- ID.l = Cvl("MAIN")
- Tag.l = 1
-
-
- ; Use FindPreferences_ to check that the item has been stored
- *prefstruct.PrefsStruct = FindPreferences_(*prefhandle, ID, Tag)
- If *prefstruct
- NPrint "Preference data found!"
-
- ; And finally, just to show that the preference data was stored,
- ; we use GetPreferences_ to retrieve the data from memory
- datasize.l = GetPreferences_(*prefhandle, ID, Tag, &temp(0), 256)
- NPrint "Contents of pref data:"
- NPrint Peek$(&temp(0))
- End If
-
-
- ; now we want to set a new value for it
- NPrint "Please enter new string for preference (blank string to not do anything)"
- prefdata$ = Edit$(256)
- If prefdata$<>""
- SetPreferences_ *prefhandle, ID, Tag, &prefdata$, Len(prefdata$)+1
-
- ; And save the preferences out again. run this program again if you
- ; want to check the changes
- WritePrefsHandle_ *prefhandle,preffile$
- End If
-
- ; Finally we free the prefs handle
- FreePrefsHandle_ *prefhandle
- End If
-
- NPrint "Press LMB+RMB to quit"
- While Joyb(0)<>3
- Delay_ 1
- Wend
- End
-
-